class GamePausePanel extends BasePanel{

	/**开始游戏 */
	private startImg:eui.Image;
	/**重新开始游戏 */
	private restartImg:eui.Image;
	/**返回主页 */
	private goHomeImg:eui.Image;
	/**声音 */
	private soundImg:eui.Image;

	public constructor(index:number = GameConfig.uiIndex.pause) {
		super(index);
		this.skinName = "gamePausePanelSkin";
	}

	/**添加监听 */
	public addListener(){
		this.startImg.addEventListener(egret.TouchEvent.TOUCH_TAP,this.startGame,this);
		this.restartImg.addEventListener(egret.TouchEvent.TOUCH_TAP,this.reStartGame,this);
		this.goHomeImg.addEventListener(egret.TouchEvent.TOUCH_TAP,this.goHome,this);
		this.soundImg.addEventListener(egret.TouchEvent.TOUCH_TAP,this.soundConfigChange,this);
		this.updateSound();
		
	}
	/**移除监听 */
	public removeListener(){
		this.startImg.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.startGame,this);
		this.restartImg.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.reStartGame,this);
		this.goHomeImg.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.goHome,this);
		this.soundImg.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.soundConfigChange,this);
	}
	/**
	 * 开始游戏
	 */
	private startGame(){
		App.EventManager.dispatchEvent(GameConstants.UI_REMOVE_FROM_PARENT, this.index);
		App.EventManager.dispatchEvent(GameConstants.GAME_FINISH_PAUSE_TO_START);
	}
	/**
	 * 重新开始游戏
	 */
	private reStartGame(){
		App.EventManager.dispatchEvent(GameConstants.UI_REMOVE_FROM_PARENT, this.index);
		App.EventManager.dispatchEvent(GameConstants.GAME_FINISH_PAUSE_TO_RESTART);
	}
	/**
	 * 返回主页
	 */
	private goHome(){
		App.EventManager.dispatchEvent(GameConstants.UI_REMOVE_FROM_PARENT, this.index);
		App.EventManager.dispatchEvent(GameConstants.UI_REMOVE_FROM_PARENT, GameConfig.uiIndex.game);
		App.EventManager.dispatchEvent(GameConstants.UI_ADD_TO_PARENT, GameConfig.uiIndex.home);

	}
	/**
	 * 点击音效控制
	 */
	private soundConfigChange(){
		UserData.musicEnabled = !UserData.musicEnabled;
		// 音效设置持久化保存
		UserData.save2Local();
		this.updateSound(true);


	}

	/**
	 * 切换音效设置
	 */
	private updateSound(fromChange:boolean=false)
	{
		if(UserData.musicEnabled){
			this.soundImg.source = "pauseSoundOn_png";
			if(fromChange){
				TipsUtils.showTipsDownToUp("已开启声音");
			}
			
			SoundManager.playBgMusic();
		}else{
			this.soundImg.source = "pauseSoundOff_png";
			if(fromChange){
				TipsUtils.showTipsDownToUp("已关闭声音");
			}
			SoundManager.stopBgMusic();
		}
	}
}